package toolCategories

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import tool.Tool
import tool.ToolEvent

val toolCategories = listOf(CodeAssistantToolCategory, JsonToolCategory, MathToolCategory)

interface ToolCategory {
    fun getName(): String

    fun getTools(): List<Tool>

    @Composable
    fun Render() {
        var currentTools by remember { mutableStateOf<Tool?>(null) }
        currentTools?.Render(
            onEvent = {
                when (it) {
                    is ToolEvent.BackEvent -> {
                        currentTools = null
                    }
                }
            }
        ) ?: run {
            LazyVerticalGrid(
                columns = GridCells.Adaptive(200.dp),
                horizontalArrangement = Arrangement.spacedBy(10.dp),
                verticalArrangement = Arrangement.spacedBy(10.dp),
            ) {
                items(getTools().size) {
                    val tool = getTools()[it]
                    ToolItem(tool) {
                        currentTools = tool
                    }
                }
            }
        }
    }

    @Composable
    fun ToolCategoryIcon(modifier: Modifier)
}
